package com.zijie.shop.order.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zijie.order.model.Order;
import com.zijie.order.model.search.OrderSearchBean;
import com.zijie.order.service.OrderService;

import com.zijie.shop.order.api.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class OrderServiceImpl implements OrderService {
    private OrderMapper orderMapper;
    @Autowired
    public void setOrderMapper(OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }

    @Override
    public Page<Order> findAll(Page<Order> page, OrderSearchBean osb) {
        return   orderMapper.findAll(page,osb);

    }

    @Override
    public int deleteByIds(List<Integer> ids) {
        return orderMapper.deleteByIds(ids);
    }

    @Override
    public int deleteById(Integer id) {
        return orderMapper.deleteById(id);
    }
    @Override
    public Order findById(Integer id) {
        return orderMapper.selectById(id);
    }

    @Override
    public boolean save(Order order) {
        order.setStatus("0");
        return orderMapper.insert(order)==1;
    }

    @Override
    public boolean update(Order order) {
        return orderMapper.updateByIdUser(order);
    }

    @Override
    public boolean fahuo(Integer id) {
        boolean resulet = orderMapper.updateStatusToFaHuo(id);
        if(resulet){
            return resulet;
        }else {
            return false;
        }
    }

    @Override
    public boolean songda(Integer id) {
        boolean resulet = orderMapper.updateStatusToSongDa(id);
        if(resulet){
            return resulet;
        }else {
            return false;
        }
    }

    @Override
    public List<Order> findAll2(OrderSearchBean osb) {
        LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(Order::getMemberId,osb.getMemberId());
        queryWrapper.orderByDesc(Order::getCreateTime);
        return orderMapper.selectList(queryWrapper);
    }

}